home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / rasterops / show.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.0 KB  |  121 lines

  1. /*
  2.  * Copyright 1995, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* show.c
  19.  *    Type "show <imageFileName>" to create a window displaying any 
  20.  *      RGB image stored in the SGI .rgb format.
  21.  *
  22.  *    imageFileName is opened and the image data is read.  
  23.  *    The image is then displayed in a window.
  24.  */
  25. #include <GL/gl.h>
  26. #include <GL/glu.h>
  27. #include <GL/glut.h>
  28.  
  29. #include <math.h>
  30. #include <stdio.h>
  31. #include "rgbImageFile.h"    /* should be found in ../../include */
  32.  
  33. /*  Function Prototypes  */
  34.  
  35. GLvoid  initgfx( GLvoid );
  36. GLvoid  keyboard( GLubyte, GLint, GLint );
  37. GLvoid  drawScene( GLvoid );
  38. GLvoid  reshape( GLsizei, GLsizei );
  39.  
  40. /* Global Definitions */
  41.  
  42. #define KEY_ESC    27    /* ascii value for the escape key */
  43.  
  44. /* Global Variables */
  45.  
  46. static unsigned int    *image;
  47. static int         imageWidth, imageHeight;
  48.  
  49. void
  50. main ( int argc, char *argv[])
  51. {
  52.     glutInit( &argc,  argv );
  53.  
  54.     if (argc < 2) {
  55.         fprintf (stderr, "usage:  show <imageFileName>\n");
  56.         exit (1);
  57.     }
  58.     
  59.     image = rgbReadImageFile(argv[1], &imageWidth, &imageHeight);
  60.  
  61.     glutInitWindowPosition( 100, 100 );
  62.     glutInitWindowSize( imageWidth, imageHeight );
  63.     glutInitDisplayMode( GLUT_RGBA | GLUT_SINGLE );
  64.     glutCreateWindow( argv[0] );
  65.  
  66.     glutKeyboardFunc( keyboard );
  67.     glutReshapeFunc( reshape );
  68.     glutDisplayFunc( drawScene ); 
  69.  
  70.     glutMainLoop();
  71. }
  72.  
  73. GLvoid
  74. initgfx( void )
  75. {
  76.     glClearColor( 0.0, 0.0, 0.0, 1.0 );
  77. }
  78.  
  79. GLvoid 
  80. keyboard( GLubyte key, GLint x, GLint y )
  81. {
  82.     switch (key) {
  83.     case KEY_ESC:    /* Exit whenever the Escape key is pressed */
  84.         exit(0);
  85.     }
  86. }
  87.  
  88. GLvoid
  89. reshape( GLsizei width, GLsizei height )
  90. {
  91.     glViewport( 0, 0, width, height );
  92.  
  93.     glMatrixMode( GL_PROJECTION );
  94.     glLoadIdentity();
  95.     gluOrtho2D( 0.0, (GLdouble) width, 0.0, (GLdouble) height );
  96.     glMatrixMode( GL_MODELVIEW );
  97.     glLoadIdentity();
  98.     glTranslatef( 0.375, 0.375, 0.0 );
  99. }
  100.  
  101. GLvoid
  102. drawScene( GLvoid )
  103. {
  104.     glClear( GL_COLOR_BUFFER_BIT );
  105.  
  106.     /* Set raster position.  Note that glRasterPos2i() takes
  107.      * world coordinates, which are transformed by the current 
  108.      * MODELVIEW and PROJECTION matrices.
  109.      *
  110.      * In this example, both contain Identity matrices, 
  111.      * causing these xy coordinates to map directly to window
  112.      * coordinates.  This would not be the case if any
  113.      * projection or modeling transforms had been applied.
  114.      */
  115.     glRasterPos2i( 0,  0 );
  116.     glDrawPixels( imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, 
  117.             image );
  118.     
  119.     glFlush();
  120. }
  121.